﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Collections.Generic;


namespace GraphDrawing
{
    class Edge
    {
        //private Point v1pos;
        //private Point v2pos;

        private List<Vertex> vertexList;
        public int v1, v2;
        public int edgeId;

        public Edge(List<Vertex> vertexList, int v1, int v2)
        {
            //v1pos = vertex1Pos;
            //v2pos = vertex2pos;

            this.vertexList = vertexList;
            this.v1 = v1;
            this.v2 = v2;
        }

        public void draw(Canvas canvas, bool isDisplayPossition, int index)
        {
            Line ledge = new Line();
            ledge.Stroke = System.Windows.Media.Brushes.Blue;

            ledge.X1 = vertexList[v1].possition.X;
            ledge.Y1 = vertexList[v1].possition.Y;

            ledge.X2 = vertexList[v2].possition.X;
            ledge.Y2 = vertexList[v2].possition.Y;

            canvas.Children.Add(ledge);

            if (isDisplayPossition)
            {
                TextBlock displayPosition = new TextBlock();
                //displayPosition.Text = "[ " + possition.X.ToString() + "," + possition.Y.ToString() + " ]";
                displayPosition.Text = "( " + index.ToString() + " )";
                displayPosition.Foreground = new SolidColorBrush(Colors.Red);
                displayPosition.FontWeight = FontWeights.Bold;
                Canvas.SetLeft(displayPosition, (Math.Abs(vertexList[v1].possition.X + vertexList[v2].possition.X) / 2));
                Canvas.SetTop(displayPosition, (Math.Abs(vertexList[v1].possition.Y + vertexList[v2].possition.Y) / 2));

                canvas.Children.Add(displayPosition);
            }
        }

        public Point GetPoint(int i)
        {
            if (i == 0)
            {
                return vertexList[v1].possition;
            }

            if (i == 1)
            {
                return vertexList[v2].possition;
            }

            return new Point(0,0);
        }
    }
}
